package com.zut.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zut.dao.StudentDao;
import com.zut.domain.Student;
import com.zut.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;

    public PageInfo<Map<String, String>> getAll(Integer pageNum, Integer pageSize) {
        List<Map<String, String>> list;
        PageHelper.startPage(pageNum, pageSize);
        list = studentDao.getAll();
        return new PageInfo<>(list);
    }

    public List<Map<String, String>> getAll() {
        return studentDao.getAll();
    }

    public Student getByNP(Student student) {
        return studentDao.getByNP(student);
    }

    public boolean insert(Student student) {
        return studentDao.insert(student) > 0;

    }

    public Student selectById(String id) {
        return studentDao.selectById(id);
    }

    public Map<String, String> getById(String id) {
        Map<String, String> byId = studentDao.getById(id);
        return byId;
    }

    public boolean deleteById(String id) {
        return studentDao.deleteById(id) > 0;
    }

    public boolean update(Student student) {
        return studentDao.update(student) > 0;
    }

    public String getCoach(String id) {
        return studentDao.getCoach(id);
    }

    public String getPassword(String id) {
        return studentDao.getPassword(id);
    }

    @Override
    public PageInfo<Map<String, String>> getByCoachId(Integer pageNum, Integer pageSize, String id) {
        List<Map<String, String>> list;
        PageHelper.startPage(pageNum, pageSize);
        list = studentDao.getByCoach(id);
        return new PageInfo<>(list);
    }

    /**
     * pageHelper使用测试
     *
     * @return
     */
    public PageInfo<Map<String, String>> safePage(Integer pageNum, Integer pageSize) {
        List<Map<String, String>> list;
        PageHelper.startPage(pageNum, pageSize);
        list = studentDao.getTest();
        return new PageInfo<>(list);
    }

    public List<Student> getBestStudent() {
        return studentDao.getBestStudent();
    }

    public boolean updatePassword(HashMap<String, String> map) {
        return studentDao.updatePwd(map) > 0;
    }
}

